/*!
 * jQuery.filer
 * Copyright (c) 2015 CreativeDream
 * Website: https://github.com/CreativeDream/jquery.filer
 * Version: 1.0.5 (19-Nov-2015)
 * Requires: jQuery v1.7.1 or later
 */
!function(){
    var lybyGuide =  function() {
        "use strict";
        var hostStr = 'http://static.contest.500px.me';
        var tpl = '<div class="guidance">\
                <div class="guidance_bg"></div>\
                <div class="guidance_body">\
                </div>\
                </div>';
        var bodyTpl = {
            details : function(){
                return {
                    html : '<img id="guidance_help2" class="guidance_help" src="'+hostStr+'/lib/guide/imgs/detail_help.png" />',
                    afterRender : function(_cmp,hEl){
                        var os = _cmp.offset();
                        hEl.css({
                            top : os.top-144,
                            left : os.left-299
                        });
                    }
                }
            }(),
            rating : function(){
                return {
                    html : '<img style="display:none;" id="guidance_rating_help" class="guidance_help" src="'+hostStr+'/lib/guide/imgs/rating_help.png" />',
                    afterRender : function(_cmp,hEl){
                       setTimeout(function(){
                           $(document).scrollTop(0);
                           var os = _cmp.offset();
                           hEl.css({
                               top : os.top-147,
                               left : os.left-419
                           }).show();
                       },500)
                    }
                }
            }(),
            setCover : function(){
                return {
                    html : '<img style="display:none;" id="guidance_cover_help" class="guidance_help" src="'+hostStr+'/lib/guide/imgs/yingjifengmian.png" /><img id="guidance_share_help" style="display:none;" class="guidance_help" src="'+hostStr+'/lib/guide/imgs/set_share.png" />',
                    afterRender : function(_cmp,hEl){
                        this.hEl = hEl;
                        setTimeout(function(){
                            var os = _cmp.offset();
                            $(hEl[0]).css({
                                top : os.top - $(document).scrollTop() - 20,
                                left : os.left - 103
                            }).show();
                        },500)

                    },initEvent:function(guideDom){
                        var me = this;
                        var index = 0;
                        guideDom.click(function(e){
                            var osEl = $('.extra-actions-button.button.share');
                            if(index||!osEl.length){
                                guideDom.hide();
                                $('html').removeClass('pxLightbox');
                            }else{
                                index++;
                                $(me.hEl[0]).hide();
                                var os = osEl.offset();
                                var h2El = $(me.hEl[1]);
                                osEl.click();
                                h2El.show();
                                h2El.css({
                                    top : os.top - $(document).scrollTop()-100,
                                     left : os.left-500
                                });
                            }
                        });
                    }
                }
            }()
        };
        $.fn.lybyGuide = function(q) {
            return this.each(function(t, r) {
                var defaults = $.extend(true, {}, $.fn.lybyGuide.defaults, q);
                var me = $(tpl);
                var _cmp = $(r);
                var f = {
                    init : function(){
                        if(!$('.guidance').length){
                            //<img id="guidance_help2" class="guidance_help" src="/lib/guidance/help2.png" />
                            $(document.body).append(me);
                            $('html').addClass('pxLightbox');
                        }
                        var tplJson = bodyTpl[defaults.tpl];
                        if(tplJson){
                            var hEl = $(tplJson.html);
                            me.find('.guidance_body').html(hEl);
                            if(tplJson.afterRender instanceof Function){
                                tplJson.afterRender(_cmp,hEl);
                            }
                            if(tplJson.initEvent instanceof Function){
                                tplJson.initEvent(me);
                            }else{
                                this.initEvent();
                            }
                            this.count(defaults.tpl);
                        }
                    },initEvent:function(){
                        me.click(function(e){
                            me.hide();
                            $('html').removeClass('pxLightbox');
                        });
                    },count : function(flag){
                        if(!SJ_UT.id){
                            return;
                        }
                        $.ajax({
                            // 提交数据的类型 POST GET
                            type : "get",
                            // 提交的网址
                            url : hostStr+'/guide/count',
                            data : {
                                flag : flag,
                                userId : SJ_UT.id
                            },
                            // 提交的数据
                            dataType : 'jsonp',
                            jsonp : 'callback',
                            success : function(data) {
                                //console.log(data);
                            },
                            error : function(e) {
                            }
                        });
                    }
                };
                f.init();
                return this;
            });
        };
        $.fn.lybyGuide.defaults = {}
        var cssLink = document.createElement("link");
        cssLink.rel = "stylesheet";
        cssLink.rev = "stylesheet";
        cssLink.type = "text/css";
        cssLink.media = "screen";
        cssLink.href = hostStr+'/lib/guide/guide.css';
        document.getElementsByTagName("head")[0].appendChild(cssLink);
    };
    if(typeof module == 'undefined'){
        lybyGuide();
    }else{
        module.exports = lybyGuide;
    }
}();